﻿using ControllerClient;
using ControlMachine;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

namespace NewCash2DeviceServer
{
    class SignatureInfoHelper
    {
        static byte[] CAData = new byte[256];
        static byte[] SiGN = new byte[1024];

        [DllImport("RFIDDll.dll")]
        public static extern int RFID_SIGNSha1(byte[] SentData, byte[] CAData, byte[] SiGN);

        public static SignatureInfo getsignatureInfo(string signdata)
        {
            byte[] SentData = System.Text.Encoding.UTF8.GetBytes(signdata);
            int ret = RFID_SIGNSha1(SentData, CAData, SiGN);
            if (ret < 0)
            {
                Debug.WriteLine("签名数据获取失败");
                return null;
            }
            else
            {
                SignatureInfo sighinfo = new SignatureInfo();
                sighinfo.Cadata = ControllerClient.UserTool.StringAndBytesHelper.ToHexString(CAData, CAData.Length);

                Debug.WriteLine("SiGN=" + StringAndBytesHelper.ToHexString(SiGN, SiGN.Length));
                sighinfo.Sighdata = StringAndBytesHelper.ToHexString(SiGN, SiGN.Length).Substring(0, ret * 2);

                return sighinfo;
            }


        }
    }
}
